import Cookies from 'js-cookie'
import store from '@/store'

const TokenKey = 'Admin-Token'

export function getToken() {
  return Cookies.get(TokenKey)
}

//
// export function setToken(token) {
//   return Cookies.set(TokenKey, token)
// }
//
// export function removeToken() {
//   return Cookies.remove(TokenKey)
// }
export async function setToken(token) { // 登录后set token
  const result = Cookies.set(TokenKey, token)
  await store.dispatch('app/applicationConfiguration') // 然后 转到  @/store/modules/app.js 的 applicationConfiguration 方法
  return result
}

export async function removeToken() {
  const result = Cookies.remove(TokenKey)
  await store.dispatch('app/applicationConfiguration')
  return result
}
